package com.zyq.validation.service;

import com.zyq.validation.pojo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.validation.ConstraintViolation;
import java.util.Set;
//import jakarta.validation.Validator;

@Service
public class UserService2 {//javax.validation.Validator这种方式对于初学者不建议了解
    // (建议先了解UserService1中的org.springframework.validation.Validator)
    @Autowired
    //private jakarta.validation.Validator validator;
    private javax.validation.Validator validator;
    public boolean validateUserByJavaXValidator(User user){
        Set<ConstraintViolation<User>> sets=validator.validate(user);
        for(ConstraintViolation c:sets){
            System.err.println("------------------");
            System.err.println(c.getMessage());
            System.err.println("------------------");
        }
        return sets.isEmpty();
    }
}